{% extends "settings/base.html" %}

{% block container-right %}
{% if userPubkey_all %}
  <h2 class="heading">管理SSH公匙</h2>
  <table class="table ssh">
    <colgroup>
      <col width="">
      <col width="md5">
      <col width="status">
      <col width="action">
    </colgroup>
    <thead>
      <tr>
        <th class="first">公钥标识</th>
        <th>指纹信息</th>
        <th>状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      {% for userPubkey in userPubkey_all %}
      <tr>
        <td class="name">{{ userPubkey.name }}</td>
        <td class="md5">{{ userPubkey.fingerprint }}</td>
        <td class="status">正常</td>
        <td class="action">
          <button id="i_remove_{{ userPubkey.id }}" value="{{ userPubkey.id }}" class="removeSshpubkey btn btn-mini">删除</button>
        </td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
{% endif %}

<form id="doSshpubkeyForm" class="form-horizontal ssh" action="/settings/sshpubkey/remove/" method="post">
  {% csrf_token %}
  {{ doSshpubkeyForm.pubkey_id }}
  {{ doSshpubkeyForm.action }}
</form>

<form class="form-horizontal ssh" action="" method="post">
  <fieldset>
    <legend class="heading">添加SSH公匙</legend>
    {% csrf_token %}
    <div class="control-group">
      <label for="pubkey_name" class="control-label">公钥标识</label>
      <div class="controls">
        {{ sshpubkeyForm.pubkey_name }}
      </div>
    </div>
    <div class="control-group">
      <label for="pubkey" class="control-label">公钥</label>
      <div class="controls">
        {{ sshpubkeyForm.pubkey }}
      </div>
    </div>
    {% if error %}
    <div class="alert">
      <a data-dismiss="alert" class="close">×</a>
      <strong>出错了！</strong> {{ error }}
    </div>
    {% endif %}
    <div class="control-group">
      <div class="controls">
        <button id="addSubmit" class="btn btn-large" type="submit">添加</button>
        <p class="inner"><small><a target="_blank" href="/join/3#ssh">如何添加SSH公匙？</a></small></p>
      </div>
    </div>
  </fieldset>
</form>
{% endblock %}

{% block js %}
<script>
  $(function(){
    $('#doSshpubkeyForm').hide();
    (function(){
      $('#pubkeyName').attr('placeholder', '例如: 公司,笔记本,开发环境');
      $('#pubkey').attr('placeholder', 'id_rsa.pub文本内容, 最多10个key');
      $('#pubkeyName').addClass('input-xlarge');
      $('#pubkey').addClass('input-xlarge');
    })();
    $('.removeSshpubkey').click(
      function(){
        if($(this).text() == '删除') {
          $(this).addClass('btn-danger').text('确定删除');
          return;
        }
        if($(this).text() == '确定删除') {
          $('#pubkeyId').val($(this).val());
          $('#action').val('remove');
          $('#doSshpubkeyForm').submit()
        }
      }
      );
  });
</script>
{% endblock %}

